<!--  -->
<template>
    <div>

        <van-form @submit="onSubmit">

            <!-- 头 -->
            <div class="font15 mt10 pl10">
                <span class="titletext">{{ nFromdata.title }}</span>
                <div class="graytext mt10 font13">
                    <span>工单编号：</span>
                    <span class="titletext">{{ nFromdata.pmInsId }}</span>
                </div>
            </div>

            <section-header :sectionTitle="'商机数据'" />
            <div>
                <van-field readonly required name="opportunitiesNumber" :value="fromdata.opportunitiesNumber" label="商机编号:"
                    label-width="5em" />
                <van-field readonly required name="businessName" :value="fromdata.businessName" label="商机名称:"
                    label-width="5em" />
                <van-field readonly required name="cities" :value="fromdata.cities" label="地市:" label-width="3em" />
                <van-field readonly required name="county" :value="fromdata.county" label="县区:" label-width="3em" />
                <van-field readonly name="informant" :value="fromdata.informant" label="商机填报人:" label-width="6em" />
                <van-field readonly name="informantPhone" :value="fromdata.informantPhone" label="商机填报人联系方式:"
                    label-width="10em" />
                <van-field readonly name="currentSituation" :value="fromdata.currentSituation" label="当前形势:"
                    label-width="5em" />
                <van-field readonly autosize type="textarea" rows="1" name="dictIntroduction"
                    :value="fromdata.dictIntroduction" label="商机简介:" label-width="5em" />
                <van-field readonly name="informantDepartment" :value="fromdata.informantDepartment" label="填报人组织:"
                    label-width="6em" />
                <van-field readonly name="informantPosition" :value="fromdata.informantPosition" label="填报人岗位:"
                    label-width="6em" />
                <van-field readonly name="opportunitiesType" :value="fromdata.opportunitiesType" label="商机类型:"
                    label-width="5em" />
                <van-field readonly name="industryType" :value="fromdata.industryType" label="行业类型:" label-width="5em" />
                <van-field readonly name="withType" :value="fromdata.withType" label="业务类型:" label-width="5em" />
                <van-field readonly name="withBusiness" :value="fromdata.withBusiness" label="业务场景:" label-width="5em" />
            </div>

            <section-header :sectionTitle="'补充数据'" />
            <div>
                <van-field readonly name="projectBiddingSub" :value="fromdata.projectBiddingSub" label="项目投标主体:"
                    label-width="7em" />
                <van-field readonly name="majorSupportType" :value="fromdata.majorSupportType" label="专业公司支撑类型:"
                    label-width="9em" />
                <van-field readonly required name="supportType" :value="fromdata.supportType" label="支撑类型:"
                    label-width="5em" />
                <van-field readonly name="expectSupportTime" :value="fromdata.expectSupportTime" label="期望完成支撑时间:"
                    label-width="9em" />
                <van-field readonly required name="productCategory" :value="fromdata.productCategory" label="产品类别:"
                    label-width="5em" />
                <van-field readonly required name="productName" :value="fromdata.productName" label="产品名称:"
                    label-width="5em" />
                <van-field readonly required name="supportUnit" :value="fromdata.supportUnit" label="建议支撑单位:"
                    label-width="7em" />
                <van-field readonly required name="provinceSupport" :value="fromdata.provinceSupport" label="省公司支撑处室:"
                    label-width="8em" />
                <van-field v-if="fromdata.supportType == '沟通方案支撑'" readonly name="orderType" :value="fromdata.orderType"
                    label="工单类型:" label-width="5em" />
                <div v-if="hasSLJGModule">
                    <van-field readonly name="responsePrescription" :value="fromdata.responsePrescription" label="响应时效(天):"
                        label-width="7.5em" />
                    <van-field readonly name="preliminaryPrescription" :value="fromdata.preliminaryPrescription"
                        label="初步解决方案时效(天):" label-width="11.5em" />

                    <van-field readonly name="offerPrescription" :value="fromdata.offerPrescription" label="投标报价时效(天):"
                        label-width="9.5em" />
                    <van-field readonly name="customizedPrescription" :value="fromdata.customizedPrescription"
                        label="定制化解决方案时效(天):" label-width="12em" />
                    <van-field readonly name="exchangePrescription" :value="fromdata.exchangePrescription"
                        label="现场交流时效(天):" label-width="9.5em" />
                    <van-field readonly name="isDeliver" :value="fromdata.isDeliver" label="是否及时交付:" label-width="7em" />
                    <van-field readonly name="isSatisfied" :value="fromdata.isSatisfied" label="是否满意:" label-width="5em" />
                    <van-field readonly autosize type="textarea" rows="1" name="satisfiedEvaluate"
                        :value="fromdata.satisfiedEvaluate" label="满意评价:" label-width="5em" />
                </div>
                <van-field readonly required autosize type="textarea" rows="1" name="supportContent"
                    :value="fromdata.supportContent" label="支撑内容:" label-width="5em" />
                <van-field readonly autosize type="textarea" rows="1" name="supportRemark" :value="fromdata.supportRemark"
                    label="备注:" label-width="3em" />
                <van-field readonly label="勘察单附件:" label-width="6em" />
                <div v-for="(fileitem) in fromdata.surveyFileList" :key="fileitem.id" style="margin-left:20px">
                    <div readonly class="font14 fileLink" style="color:#0F85CF">
                        <a target="_blank" @click="openFileUrlfun(fileitem.anonymousFilePath)">{{ fileitem.fileName }}</a>
                    </div>
                </div>
            </div>

            <section-header :sectionTitle="'支撑任务受理'" />
            <div>
                <van-field readonly name="code" :value="supportTaskAcceptance.code" label="商机编码:" label-width="5em" />
                <van-field readonly name="supportType" :value="supportTaskAcceptance.supportType" label="支撑类型:" label-width="5em" />

                <van-field readonly label="支撑任务列表:" label-width="7em" />
                <el-table :data="supportTaskAcceptance.taskList" :header-cell-style="{ textAlign: 'center' }"
                    :cell-style="{ textAlign: 'center' }" border style="width: 100%">
                    <el-table-column prop="code" label="任务编码" width="110" />
                    <el-table-column prop="name" label="任务名称" />
                    <el-table-column prop="status" label="任务状态" width="200" />
                    <el-table-column prop="createTime" label="任务创建时间" width="110" />
                    <el-table-column prop="planSubmitTime" label="任务提交时间" width="110" />
                    <el-table-column prop="fileList" label="任务附件" />
                </el-table>

            </div>


            <!-- 意见按钮 -->
            <div class="left_botton">
                <button block type="button" @click="tomsg()" style="color:#60a9ec; display: inline-block;width:100%;border: 0px solid #60a9ec;border-radius: 15px 0px 0px 15px;
          padding:10px 10px 10px 15px;font-size:13px">意见</button>
            </div>


            <!-- 流转下一步 -->
            <div v-if="todotype||toRead" class="footer">
                <van-button block type="info" native-type="submit" :disabled="!canToNext"
                    style="display: inline-block; width: 100%; border: 0px solid #60a9ec">{{ buttonTitle }}</van-button>
            </div>
        </van-form>


        <!-- 当前办理人 -->
        <section-header v-if="showHistory" :sectionTitle="'当前办理人:'" />
        <div v-if="showHistory" class="font13 ptandpb10 pl16">
            <div>
                <span class="titletext font13">{{
                    historydata.MANAGER
                }}</span>
            </div>
            <div class="mt5">
                <span class="graytext font12">{{ historydata.DEPARTMENT }}</span>
            </div>
        </div>


        <!-- 审批意见 -->
        <section-header id="opinion" :sectionTitle="'审批意见:'" />
        <opinion-item :approveList="approveList" />


    </div>
</template>


<script>

import { mapGetters } from "vuex";
import { Notify, Toast } from "vant";
import { openFileUrl } from "@/store/openFile";
import util from "@/assets/js/public";
import {
    getZXGSSPFormDetail,
    getSynergySupportByPmInsId,
    getPreTaskSyncByPmInsId,
    queryBySupportUnit,
    getWfOptMags,
    getWfLinkTracks,
} from "@/api/dictapi";
import SectionHeader from '../sztdzj/sztdzjDetail/section-header.vue';
import OpinionItem from '../sztdzj/sztdzjDetail/opinion-item.vue';


export default {
    data() {
        return {
            fromdata: {},
            nFromdata: {},
            supportTaskAcceptance:{},

            showHistory: false,
            historydata: {},
            approveList: [],


            params: this.$route.query,
            todotype: false,
            toRead:false,
            buttonTitle: '流转下一步',
            canToNext: true,

        };
    },

    computed: {

        ...mapGetters(["user"]),
        ...mapGetters(["userinfo"]),

        /// 响应时效(天)、初步解决方案时效(天)、是否及时交付、是否满意、满意评价
        hasSLJGModule() {
            return false;
        },
    },

    //生命周期--创建完成
    created() {

        console.log("项目列表类型：" + this.params.todoType);
        console.log("用户信息：", JSON.stringify(this.userinfo));

        if (this.params.todoType == "1") {
            this.todotype = true;
        } else if (this.params.todoType == "2") {
            this.showHistory = true;
        }else if (this.params.todoType == "3") {
            this.toRead = true;
        }

        if (this.params.location == 'dict.start' ||
            this.params.location == 'dict.toStart') {
            this.canToNext = false;
            this.buttonTitle = '暂不支持该环节,请至PC端办理';
        }

        this.getdetail();
    },

    //生命周期--挂载完成
    components: {
        SectionHeader,
        OpinionItem

    },

    //生命周期--挂载完成
    mounted() { },

    //方法调用
    methods: {

        tomsg() {
            document.getElementById('opinion').scrollIntoView({ behavior: 'smooth' })
        },

        openFileUrlfun(value) {
            this.$router.push(
                {
                    name: 'fileview',
                    query: {
                        openFileUrl: openFileUrl(value)
                    }
                }
            );
        },

        
        getdetail() {

            Toast.loading({ message: "加载中", forbidClick: false });
            getZXGSSPFormDetail(Object.assign(this.params, { userName: this.user.userName })).then((result) => {
                this.fromdetal = {};
                Toast.clear();

                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    this.nFromdata = result.data.data;
                }

            })

            getSynergySupportByPmInsId( Object.assign(this.params, { userName: this.user.userName }) ).then((result) => {
                this.fromdetal = {};
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {

                    this.fromdata = result.data.data;
                    if (this.fromdata.supportTaskAcceptance != null) {
                        this.supportTaskAcceptance = this.fromdata.supportTaskAcceptance;
                    }

                    this.getSupportUnitValue();
                }
            })

            getWfOptMags(Object.assign(this.params), { userName: this.user.userName }).then((result) => {
                Toast.clear();
                if (!result.data) {
                    Notify(result.message);
                    return;
                }
                this.approveList = result.data.data.reverse();
            })

            if (this.showHistory) {

                getWfLinkTracks(Object.assign(this.params), { userName: this.user.userName }).then((result) => {
                    Toast.clear();
                    if (!result.data) {
                        Notify(result.message);
                        return;
                    }
                    if (result.data.data) {
                        //数据过滤，并生成新的数组
                        this.historydata = result.data.data.filter(
                            (item) => item.CURRENTSTATE == 10
                        )[0];
                        if (this.historydata) {
                            if (this.historydata.MANAGER) {
                                this.showHistory = true;
                            } else {
                                this.showHistory = false;
                            }
                        } else {
                            this.showHistory = false;
                        }
                    } else {
                        this.showHistory = false;
                    }
                })
            }
        },

        /// 获取汉字值
        getSupportUnitValue() {

            queryBySupportUnit({ userName: this.user.userName, productCategory:this.fromdata.productCategory, productName: this.fromdata.productName }).then((result) => {

                if (!result.data) {
                    Notify(result.message);
                    return;
                }

                if (result.data.data) {
                    
                    const arr = result.data.data;
                    if (Array.isArray(arr)) {
                        for (const dict of arr) {
                            if (this.fromdata.supportUnit == dict.value) {
                                this.fromdata.supportUnit = dict.name;
                                return;
                            }
                        }
                    }
                }
            })
        },


        /// 流转下一步
        pushSubmitView() {

            //提交流转
            console.log("传给递交页面:", this.params)
            console.log("formDataformData", JSON.stringify(this.mFromdata));
            var formSendData = { "htmlParamMap": {} };
            formSendData.htmlParamMap = this.mFromdata;
            formSendData.id = this.nFromdata.id;
            formSendData.pmInsId = this.nFromdata.pmInsId;
            formSendData.processType = this.params.pmInsType;
            formSendData.workItemId = this.params.workItemId;

            var params1 = {
                kv: {
                    currentUserCode: util.encrypt(this.params.userName),
                    source: 'MOBILE',
                    location: this.params.location,
                    processInstId: this.params.processInstId,
                    processDefName: this.params.processDefName,
                    processType: this.params.pmInsType,
                },
            };
            var params2 = {
                kv: {
                    "currentUserCode": util.encrypt(this.params.userName),
                    "source": 'MOBILE',
                    "location": this.params.location,
                    "processInstId": this.params.processInstId,
                    'processType': this.params.pmInsType,
                    'receiptCode': this.params.processInstId
                },
            };
            var params3 = {
                kv: {
                    "source": 'MOBILE',
                    "currentUserCode": util.encrypt(this.params.userName),
                    "workItemId": this.params.todoType==3?"":this.params.workItemId,
                    "processInstId": this.params.processInstId,
                    "location": this.params.location,
                    "notificationId":this.params.todoType==3?this.params.wfnid:""
                },
            };
            localStorage.setItem('submitPageParam', JSON.stringify({
                    getDecisionsUrl: 'decisionAndUser$api$getDecisions',
                    getUserUrl: 'decisionAndUser$api$getOrgAndUser',
                    tosubmintUrl: 'applicationFormProject$api$startSubmitProcess',

                    getDecisionsParams: params1,
                    getUserParams: params2,
                    tosubmintParams: params3,
                    formData: formSendData,
                    fromMoa:this.params.fromMoa,
                    type:this.params.todoType==3?"toRead":"toDo"
                }));
            this.$router.push({
                name: "srqrsubmit"
            });
        },

        onSubmit() {


            this.pushSubmitView();
            // getPreTaskSyncByPmInsId(Object.assign(this.params, { userName: this.user.userName })).then((result) => {

            //     Toast.clear();
            //     if (!result.data) {
            //         Notify(result.message);
            //         return;
            //     }

            //     if (result.responseid == 1) {

            //     }
            //     else
            //     {
            //         Notify({ type: 'warning', message: result.message })
            //     }
            // })
        },

    },
};
</script>

<style  scoped>
/* @import url();*/
::v-deep .el-table::before {
    height: 0;
}
</style>